package Mediator

import "fmt"

type Mediator interface {
	Communicate(who string)
}

type WildStallion interface {
	SetMediator(m Mediator)
}

type Bill struct {
	mediator Mediator
}

func (b *Bill) SetMediator(m Mediator) {
	b.mediator = m
}

func (b *Bill) Respond() {
	fmt.Println("Bill:What?")
	b.mediator.Communicate("bill")
}

type Ted struct {
	mediator Mediator
}

func (t *Ted) Talk() {
	fmt.Println("Ted:Bill?")
	t.mediator.Communicate("ted")
}

func (t *Ted) SetMediator(m Mediator) {
	t.mediator = m
}

func (t *Ted) Respond() {
	fmt.Println("Ted:How are you today?")
}

type ConcreteMediator struct {
	Bill
	Ted
}

func NewMediator() *ConcreteMediator {
	m := &ConcreteMediator{}
	m.Bill.SetMediator(m)
	m.Ted.SetMediator(m)
	return m
}

func (m *ConcreteMediator) Communicate(who string) {
	if who == "ted" {
		m.Bill.Respond()
	} else {
		m.Ted.Respond()
	}
}
